<template>
  <div class="personaldd">
    <div class="weipdd">
      <p>我的订单</p>
    </div>
    <div class="lbpdd">
      <table style="width: 98%; text-align: center">
        <tr style="height: 60px; background-color: #e8e8e8">
          <th>宝贝</th>
          <th>单价</th>
          <th>商品操作</th>
          <th>实付款</th>
          <th>交易操作</th>
        </tr>
      </table>
    </div>
    <ul class="pddul">
      <li
        v-for="(item, index) in datas"
        @click="clickItem(index)"
        :key="index"
        :ref="index"
        class="pddlb"
      >
        <p>
          订单号： {{ item.orders_id }}
          <span class="pddtdbutton" @click="del(item.orders_id)">删除此订单</span>
        </p>
        <div class="pdduldiv" style="display: none">
          <table style="width: 100%">
            <tr>
              <td>
                <img :src="item.orders_goods_img" alt="" />
                <p>{{ item.orders_goods_title }}</p>
              </td>
              <td>
                <span style="margin-left: 29%"
                  >￥{{ item.orders_goods_price }}</span
                >
              </td>
              <td>
                <span style="margin-left: 47%">{{
                  item.orders_goods_count
                }}</span>
              </td>
              <td>
                <span style="margin-left: 29%">￥{{ item.orders_total }}</span>
              </td>
            </tr>
          </table>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: "PersonalDd",
  data() {
    return {
      flag: true,
      arr: ["和", "啊", "嗯", "哦"],
      datas: [],
      result: 0,
    };
  },
  methods: {
    del(id){
      this.$axios.post("/api/order/changePersonalOrder",{
        orders_id:id,
        user_id:localStorage.getItem("user_id")
      }).then((res)=>{
        this.$router.go(0)
      })
    },
    clickItem(index) {
      if (this.$refs[index][0].childNodes[1].style.display == "none") {
        this.$refs[index][0].childNodes[1].style.display = "block";
      } else if (this.$refs[index][0].childNodes[1].style.display == "block") {
        this.$refs[index][0].childNodes[1].style.display = "none";
      }
    },
  },
  created() {
    this.$axios
      .get("/api/order/getPayedUserOrder", {
        params: {
          user_id: localStorage.getItem("user_id"),
        },
      })
      .then((res) => {
        this.datas = res.data.results;
      });
  },
};
</script>

<style>
.personaldd {
  width: 87%;
  margin-left: 20px;
  padding: 0 20px;
  border: 1px solid #000;
}

.weipdd p {
  margin-top: 20px;
  margin-bottom: 9px;
}
.weipdd > p:nth-child(1) {
  height: 40px;
  line-height: 40px;
  font-size: 18px;
  font-weight: 600;
}
.lbpdd th:nth-child(1) {
  width: 50%;
}
.lbpdd th:nth-child(3) {
  width: 11%;
}
.lbpdd th:nth-child(4) {
  width: 8%;
}
.pddul {
  width: 98%;
  padding: 0;
  border: 1px solid #ccc;
  border-bottom-color: transparent;
}
.pddul p {
  margin: 0;
  padding: 0;
}
.pddul p:nth-child(1) {
  height: 60px;
  line-height: 60px;
  padding-left: 15px;
}
.pddlb {
  width: 100%;
  background-color: #f5f5f5;
  border-bottom: 1px solid #ccc;
}
.pddlb>p:nth-child(1) {
    cursor: pointer;
}
.pddtdbutton {
  width: 60%;
  height: 30px;
  color: blue;
  margin-left: 62%;
  text-decoration: underline;
  cursor: pointer;
}

.pdduldiv tr {
  margin-bottom: 10px;
  width: 100%;
  height: 100px;
  background-color: #fff;
}
.pdduldiv tr td:nth-child(1) {
  width: 50%;
  line-height: 30px;
  border: 1px solid #ccc;
}
.pdduldiv tr td:nth-child(1) p {
  float: left;
  margin-left: 5%;
  width: 62%;
  line-height: 75px;
  overflow: hidden; /*内容会被修剪，并且其余内容是不可见的。*/
  text-overflow: ellipsis; /*显示省略符号来代表被修剪的文本*/
  white-space: nowrap; /*文本不会换行，文本会在在同一行上继续，直到遇到 <br> 标签为止。*/
}
.pdduldiv tr td:nth-child(1) img {
  float: left;
  width: 18%;
  height: 90px;
  border: 1px solid #ccc;
  margin-left: 5px;
}
.pdduldiv tr td:nth-child(2),
.pdduldiv tr td:nth-child(3),
.pdduldiv tr td:nth-child(4) {
  width: 10%;
  line-height: 30px;
  border: 1px solid #ccc;
}
.pdduldiv tr td:nth-child(5) {
  width: 20%;
  border: 1px solid #ccc;
}
</style>